//
//  midView.m
//  BeautifulLockerRoom
//
//  Created by mac on 16/7/28.
//  Copyright © 2016年 Winny. All rights reserved.
//

#import "MidView.h"

@implementation MidView

-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self = [[MidView alloc]initWithFrame:CGRectMake(0, 160, WINDOWWIDTH, 600)];
        [RequestTool getNetworkRequestWithUrl:MODEL_LIST_URL date:^(NSDictionary *dic)
        {
            NSArray * data = [dic objectForKey:@"data"];
            [self topImageWithDic:data[0]];
            [self midImageWithDic:data[1]];
            [self bottomImageWithDic:data[2]];
            
            
        }];
        
    }
    return self;
}

-(void)topImageWithDic:(NSDictionary *)dic
{
    NSDictionary * content_data = [dic objectForKey:@"content_data"];
    
    NSString * pic_url = [content_data objectForKey:@"pic_url"];
    
    //NSLog(@"pic_url----%@",pic_url);
    
    UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WINDOWWIDTH, 100)];
    image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:pic_url]]];
    [self addSubview:image];
}

-(void)midImageWithDic:(NSDictionary *)dic
{
    NSDictionary * content_data = [dic objectForKey:@"content_data"];
    NSString * title = [content_data objectForKey:@"title"];
    NSString * sub_title = [content_data objectForKey:@"sub_title"];
    //NSLog(@"title ---%@",title);
   
    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 90, 20)];
    label1.font = [UIFont systemFontOfSize:16];
    label1.text = title;
    label1.textColor = [UIColor lightGrayColor];
    
    UILabel * label2 = [[UILabel alloc]initWithFrame:CGRectMake(100, 105, 90, 20)];
    label2.font = [UIFont systemFontOfSize:14];
    label2.text = sub_title;
    label2.textColor = [UIColor grayColor];
    
    NSArray * left_part = [content_data objectForKey:@"left_part"];
    NSArray * right_part = [content_data objectForKey:@"right_part"];
    NSDictionary * leftDic = left_part[0];
    NSDictionary * rightDic0 = right_part[0];
    NSDictionary * rightDic1 = right_part[1];
    NSString * left_pic_url = [leftDic objectForKey:@"pic_url"];
    NSString * right_pic_url0 = [rightDic0 objectForKey:@"pic_url"];
    NSString * right_pic_url1 = [rightDic1 objectForKey:@"pic_url"];
    
    
    UIImageView * leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 130, WINDOWWIDTH/2- 1,180)];
    leftImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:left_pic_url]]];
    
    
    UIImageView * rightImage0 = [[UIImageView alloc]initWithFrame:CGRectMake(WINDOWWIDTH/2 + 1, 130, WINDOWWIDTH/2 - 1,89)];
    
    rightImage0.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:right_pic_url0]]];
    
    
    UIImageView * rightImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(WINDOWWIDTH/2 + 1, 130+90+1, WINDOWWIDTH/2,89)];
    rightImage1.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:right_pic_url1]]];
    
    
    [self addSubview:label1];
    [self addSubview:label2];
    [self addSubview:leftImage];
    [self addSubview:rightImage0];
    [self addSubview:rightImage1];
    
    
}

-(void)bottomImageWithDic:(NSDictionary *)dic
{
    NSDictionary * content_data = [dic objectForKey:@"content_data"];
    NSString * title = [content_data objectForKey:@"title"];
    NSString * sub_title = [content_data objectForKey:@"sub_title"];
    
    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 315, 90, 20)];
    label1.font = [UIFont systemFontOfSize:16];
    label1.text = title;
    label1.textColor = [UIColor lightGrayColor];
    
    UILabel * label2 = [[UILabel alloc]initWithFrame:CGRectMake(100, 315, 90, 20)];
    label2.font = [UIFont systemFontOfSize:14];
    label2.text = sub_title;
    label2.textColor = [UIColor grayColor];
    
    NSArray * left_part = [content_data objectForKey:@"left_part"];
    NSArray * right_part = [content_data objectForKey:@"right_part"];
    NSDictionary * leftDic0 = left_part[0];
    NSDictionary * leftDic1 = left_part[1];
    NSDictionary * rightDic0 = right_part[0];
    NSDictionary * rightDic1 = right_part[1];
    NSString * left_pic_url0 = [leftDic0 objectForKey:@"pic_url"];
    NSString * left_pic_url1 = [leftDic1 objectForKey:@"pic_url"];
    NSString * right_pic_url0 = [rightDic0 objectForKey:@"pic_url"];
    NSString * right_pic_url1 = [rightDic1 objectForKey:@"pic_url"];
    
    
    UIImageView * leftImage0 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 340, WINDOWWIDTH/2 - 1,89)];
    leftImage0.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:left_pic_url0]]];
    
    UIImageView * leftImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 431, WINDOWWIDTH/2 - 1 ,89)];
    leftImage1.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:left_pic_url1]]];
    
    
    UIImageView * rightImage0 = [[UIImageView alloc]initWithFrame:CGRectMake(WINDOWWIDTH/2 + 1, 340, WINDOWWIDTH/2 - 1,89)];
    
    rightImage0.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:right_pic_url0]]];
    
    
    UIImageView * rightImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(WINDOWWIDTH/2 + 1, 431, WINDOWWIDTH/2 - 1,89)];
    rightImage1.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:right_pic_url1]]];

    
    [self addSubview:label1];
    [self addSubview:label2];
    [self addSubview:leftImage0];
    [self addSubview:leftImage1];
    [self addSubview:rightImage0];
    [self addSubview:rightImage1];

}
@end
